<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <script src="__JS__/jquery.js"></script>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
</head>
<body>
<div style="height: 10px;"></div>
    <div style="width:500px;margin: 0 auto;">
        <form class="layui-form" action="" id="tea">
            <input  type="hidden" name="id" value="{$id}"/>
            <input  type="hidden" name="newimage" id="newimage"/>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" required value="{$result.name}" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">价格(大杯)</label>
                <div class="layui-input-block">
                    <input type="text" name="largeprice" required value="{$result.largeprice}"  lay-verify="required" placeholder="请输入价格(元)" autocomplete="off" class="layui-input">
                </div>
            </div>
           <!--  <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">价格(中杯)</label>
                <div class="layui-input-block">
                    <input type="text" name="inprice" required  value="{$result.inprice}" lay-verify="required" placeholder="请输入价格(元)" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px">价格(小杯)</label>
                <div class="layui-input-block">
                    <input type="text" name="smallprice" required value="{$result.smallprice}" lay-verify="required" placeholder="请输入价格(元)" autocomplete="off" class="layui-input">
                </div>
            </div> -->
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 110px">原图片</label>
                <div class="layui-input-block">
                    <img src="__ROOT__\\{$result.image}" width="100" height="100">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 110px">新图片</label>
                <button type="button" class="layui-btn" id="uploadimage">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
            </div>
            <div class="layui-form-item" id="images" style="display: none">
                <label class="layui-form-label" style="width: 110px">新图片</label>
                <div class="layui-input-block">
                    <img src="" width="100" id="nimage" height="100">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" onclick="update()" class="btn btn-primary">立即修改</button>

                    <button type="button" onclick="reset()" class="btn btn-warning">重置</button>
                </div>
            </div>
        </form>
    </div>
</body>
<script>
    //初始化表单
    layui.use('form', function(){
        var form = layui.form;
    });
    //上传
    layui.use('upload', function(){
        var id = $("input[name=id]").val();
        var upload = layui.upload;
        upload.render({
            elem: '#uploadimage' //绑定元素
            ,url: "{:url('index/tea/upload')}?id="+id //上传接口
            ,done: function(res){
                if(res.success){
                    console.log(1);
                    $("#nimage").attr('src',"__ROOT__\\"+res.success);
                    $("#newimage").val(res.success);
                    $("#images").css('display','block');
                }else if(res.error){
                    layer.msg(res.error,{icon:1,time:3000});
                }
            }
        });
    });
    //修改
    function update() {
        $.ajax({
            url:"{:url('index/tea/update')}",
            data:$("#tea").serialize(),
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.msg(res.success,{icon:1,time:2000},function () {
                        //获取窗口索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭弹出的子页面窗口
                        parent.layer.close(index);
                        //刷新
                        window.parent.location.reload();
                    });
                }else if(res.error){
                    layer.msg(res.error,{icon:2,time:3000});
                }
            }
        });
    }
    //重置
    function reset() {
        $("#tea").reset();
    }
</script>
</html>